package com.yuanli.ksads.utils;

import android.app.Activity;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;

import com.kwad.sdk.api.KsAdSDK;
import com.kwad.sdk.api.KsLoadManager;
import com.kwad.sdk.api.KsScene;
import com.kwad.sdk.api.KsSplashScreenAd;
import com.kwad.sdk.api.model.SplashAdExtraData;
import com.yuanli.ad.constants.AdConstants;
import com.yuanli.ksads.AdStateListener;
import com.yuanli.ksads.KsManagerHolder;
import com.yuanli.ksads.constants.KsBean;

public class KsSplashAdUtils  {
    // 1.请求开屏广告，获取广告对象，KsFullScreenVideoAd
    public void loadKSAdSplash(final Activity activity, final AdStateListener adStateListener){
        KsManagerHolder.init(activity,new KsBean(AdConstants.AD_APP_NAME,
                "2117100003",21171000005L));

        KsManagerHolder.setInitListener(new KsManagerHolder.InitListener() {
            @Override
            public void onSuccess() {
                SplashAdExtraData extraData = new SplashAdExtraData();
                extraData.setDisableShakeStatus(false);
                KsScene scene = new KsScene.Builder(InitUtils.getBean().getSplashId()).setSplashExtraData(extraData).build(); // 此为测试posId，请联系快手平台申请正式posId

                if (KsAdSDK.getLoadManager() != null) {
                    KsAdSDK.getLoadManager().loadSplashScreenAd(scene, new KsLoadManager.SplashScreenAdListener() {
                        @Override
                        public void onError(int code, String msg) {
                            Log.e("KSADS","onError "+code+"--"+msg );
                            adStateListener.onClose();
                        }

                        @Override
                        public void onRequestResult(int adNumber) {
                            Log.e("KSADS","开屏广告广告请求填充 " + adNumber);
                        }

                        @Override
                        public void onSplashScreenAdLoad(@Nullable KsSplashScreenAd ksSplashScreenAd) {
                            Log.e("KSADS","onSplashScreenAdLoad " );
                            View splashView = ksSplashScreenAd.getView(activity,
                                    new KsSplashScreenAd.SplashScreenAdInteractionListener() {
                                        @Override
                                        public void onAdClicked() {
                                        }

                                        @Override
                                        public void onAdShowError(int i, String s) {
                                            Log.e("KSADS","onAdShowError "+i+"--"+s );
                                            adStateListener.onClose();
                                        }

                                        @Override
                                        public void onAdShowEnd() {
                                            Log.e("KSADS","onAdShowEnd " );
                                        }

                                        @Override
                                        public void onAdShowStart() {
                                            Log.e("KSADS","onAdShowEnd " );
                                        }

                                        @Override
                                        public void onSkippedAd() {
                                            Log.e("KSADS","onSkippedAd " );
                                            adStateListener.onClose();
                                        }

                                        @Override
                                        public void onDownloadTipsDialogShow() {
                                            Log.e("KSADS","onDownloadTipsDialogShow " );
                                        }

                                        @Override
                                        public void onDownloadTipsDialogDismiss() {
                                            Log.e("KSADS","onDownloadTipsDialogDismiss " );
                                        }

                                        @Override
                                        public void onDownloadTipsDialogCancel() {
                                            Log.e("KSADS","onDownloadTipsDialogCancel " );
                                        }
                                    });

                            adStateListener.onAdLoadSuccess(splashView);

                        }

                    });
                }
            }

            @Override
            public void onError(String msg) {
                Log.e("KSADS","onError "+msg );
            }
        });

    }

}
